﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiNing.Tools;
using YiNing.UI.Forms;

namespace LixunYueNan
{
    public class ErrorCodes
    {
        [Category("其他参数")]
        [DisplayName("错误代码")]
        [Description("添加相应的错误代码信息")]
        public List<ErrorCode> ErrorCodeCustomer { get; set; }

        public ErrorCodes()
        {
            ErrorCodeCustomer = new List<ErrorCode>();
        }
        public void SaveThis()
        {
            JsonHelper.Serialize(this, GetThisFileName());
        }

        /// <summary>
        /// 加载配置
        /// </summary>
        /// <returns></returns>
        public static ErrorCodes LoadThis()
        {
            var res = JsonHelper.DeserializeByFile<ErrorCodes>(GetThisFileName());
            if (res == null)
            {
                DarkMessageBox.ShowWarning("加载配置文件异常,参数初始化");
                res = new ErrorCodes();
            }
            return res;
        }
        /// <summary>
        /// 获取本身的文件名
        /// </summary>
        /// <returns></returns>
        public static string GetThisFileName()
        {
            string name = "Plugins/LixunYueNan/errcode.zyn";
            return Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, name);
        }
    }

    public enum ResultTypeCn
    {
        OK = 0,//AOI端没有OK项，这里从aoi转换后要加1
        默认,
        本体定位,
        焊盘定位,
        偏移,
        少锡,
        多锡,
        虚焊,
        假焊,
        空焊,
        立碑,
        少件,
        多件,
        错件,
        翻件,
        连桥,
        丝印,
        极性,
        翘脚,
        损件,
        PIN歪,
        散热片漏贴,
        插反,
        浮高,
        距离,
        平面度,
        尺寸
    }

    public class ErrorCode
    {
        [Category("参数绑定")]
        [DisplayName("设备错误信息序号")]
        [Description("AOI对应的错误信息序号")]
        [ReadOnly(true)]
        public int ErrorCodeIndex { get; set; }

        [Category("参数绑定")]
        [DisplayName("设备错误信息")]
        [Description("AOI对应的错误信息")]
        [ReadOnly(true)]
        public string ErrorCodeAOI { get; set; }

        [Category("参数绑定")]
        [DisplayName("MES对应的错误信息")]
        [Description("MES对应的错误信息")]
        public string ErrorCodeMES { get; set; }
    }
}
